package com.reebake.ideal.crypto.config;

import com.reebake.ideal.crypto.core.SecretKeyService;
import com.reebake.ideal.crypto.handler.DefaultSecretKeyService;
import com.reebake.ideal.crypto.properties.CryptoProperties;
import com.reebake.ideal.crypto.util.JwtUtil;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
@EnableConfigurationProperties(CryptoProperties.class)
@Import(JwtUtil.class)
public class CryptoAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public PasswordEncoder passwordEncoder() {
        return PasswordEncoderFactories.createDelegatingPasswordEncoder();
    }

    @Bean
    @ConditionalOnMissingBean
    public SecretKeyService secretKeyService() {
        return new DefaultSecretKeyService();
    }

}
